auto();

var str;
var url = new Array();
url[0] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765249050973851392&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//18703854647
url[1] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765248068751723264&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//18703854647@139
url[2] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765247082184323328&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//15311421574
url[3] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765245794080016256&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a7441638373
url[4] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765244492067387264&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//13353666935
url[5] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=765243363489236992&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a7441638375
url[6] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765242592819430912&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a7441638379
url[7] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765241989955330176&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//18055891142
url[8] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=765241417759999616&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//15294757954
url[9] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=765240073829502720&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a7441638371
url[10] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765239446185458944&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//lipb
url[11] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765238542119996544&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a74416383712
url[12] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765236773096799104&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//15395011957
url[13] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765235451245122304&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a74416383713
url[14] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765234360566694912&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket";//a7441638376
url[15] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765233705340908160&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket"//a13353666935
url[16] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765232843210110592&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket"//1805591143
url[17] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46929&shareId=765231827760727168&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket"//a7441638372
url[18] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765230743768007808&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket"//15311434852
url[19] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765229123038614656&hwFullScreen=1&shareTo=hwid&shareFrom=appmarket"//15311434821
url[20] = "https://uowap.hicloud.com/appdl-uomp-cn/campaignpreview/af8e7e9a-c3be-4463-83e2-1f6d94f980d3/index.html?page=campaign&productId=&campaignId=46954&shareId=765257543835459072&hwFullScreen=1&shareTo=weixin&shareFrom=appmarket"//15188396935



console.show();
sleep(1000)
console.setSize(device.width, device.height / 5);
console.hide()
threads.start(function () {
    //在新线程执行的代码
    while (true) {
        if (text("输入帐号密码").findOne(100)) {
            sleep(2000)
            setText(0, "Hw@12576")
            sleep(5000)
            点击文字("确定")
            sleep(5000)
            点击文字("确定")

        }
 if (textContains("无法获取数据").findOne(100)) {
            sleep(2000)
            点击文字("确定")
            点击文字("登录")
            click("登录")
        }
        if (text("同意").findOne(100)) {
            sleep(2000)
            点击文字("同意")
            click("同意")
        }
        if (textContains("帐号或密码错误").findOne(100)) {
           
            点击文字("确定")
            sleep(1000)
        获取账号();
        while (!setText(0, str));
        sleep(1000)
            点击文字("登录")

        }
        if (textContains("当前选择的国家/地区为").findOne(100)) {
            点击文字("确定")
        }
        if (textContains("未登录").findOne(100)) {
           click(850,1280)
            

        }
        子线程点击文字("变更通知", "同意")
         子线程点击文字("下一步", "下一步")
        子线程点击文字("下一页", "下一页")
        子线程点击文字("华为应用内支付", "取消")
      子线程点击文字("继续", "继续")
      子线程点击文字("立即切换", "立即切换")
        子线程点击文字("准备新的国家或地区银行卡", "确定")
        子线程点击文字("更改国家或地区", "更改国家或地区")
        子线程点击文字("暂不安装", "暂不安装")
        子线程点击文字("本服务需联网，调用存储、电话 (读取设备通话状态和识别码)、相机、信息、通讯录、日历权限，并需获取华为帐号信息、设备信息、网络信息、服务使用信息和您选择上传的数据。点击“同意”，即表示您同意上述内容及关于华为云空间与隐私、云空间用户协议。 ", "不同意")
        子线程点击文字("继续使用", "继续使用")
        子线程点击文字("紧急联系人可帮助您找回", "取消")
        子线程点击文字("为了帐号安全，需绑定安全手机号", "取消")
        子线程点击文字("下次再说", "下次再说")
        子线程点击文字("如需使用云空间", "确定")
        //子线程点击文字("通知栏显示活动、中奖、评论等消息", "同意")
        //子线程点击文字("内容详情请参阅最新的关于华为应用市场与隐私的声明", "同意")
        if (textContains("无法连接服务器").findOne(100)) {
            点击文字("确定")
            点击文字("登录");
        }
         if (textContains("以下应用将退出当前帐号").findOne(100)) {
            click("退出帐号")
        }
        if (textContains("销户").findOne(100)) {
            back()
        }
        if (textContains("允许手机在接触").findOne(100)) {
            back()
        }
        if (textContains("自动读取短信验证码").findOne(100)) {
            back()
        }
        if (textContains("即表示您同意上述内容及华为云空间用户").findOne(100)) {
            back()
        }
        
        if (textContains("如何通过紧急联系人找回帐号密码").findOne(100)) {
            back()
        }
    }
});
//签到账号循环
//重启设置()
//for (var j =  20; j >=0; j--) {
for (var j =  0; j <21; j++) {
    var 异常账号数量 = 0;
    var 正常签到数量 = 0;
    launchApp("设置");

    while (正常签到数量 < 10) {
        sleep(1000);
        退出账号();
        登陆华为账号(url[j], j);


    }
    //日志记录该账号签到情况
    log(正常签到数量);
    var sendText=(j+1)+"邀请完毕，有" + 异常账号数量 + "个账号异常"
     launchApp("AirDroid")
    console.log(sendText);
    
    
    //跳转到下一个账号
    拨号换ip();
    异常账号数量 = 0;
    正常签到数量 = 0;
    sleep(5000);
}
threads.shutDownAll()
home();
alert("执行完毕")
function 获取账号() {
    //  log("获取账号")
    try {
        var r = http.get("http://106.15.4.241:8669/huawei/one");
        str = r.body.string().replace("/[\r\n]/g", "");
        console.log(str);
    } catch (err) {
        获取账号()
    }

}

function 退出账号() {
    // log("退出账号")
    //退出华为账号***********************************************************
    if ((text("无线和网络").findOne(100)&&text("设置紧急联系人提升帐号安全").findOne(100))||text("华为帐号、付款与账单、云空间等").findOne(100)||text("华为帐号、云空间等").findOne(100)) {
        if(text("设置紧急联系人提升帐号安全").findOne(100)){
         点击文字("设置紧急联系人提升帐号安全");
        }
        if(text("华为帐号、付款与账单、云空间等").findOne(100)){
            点击文字("华为帐号、付款与账单、云空间等");
           }
           if(text("华为帐号、云空间等").findOne(100)){
            点击文字("华为帐号、云空间等");
           }
        
        
        sleep(2000)
        点击文字("退出帐号");
        //点击文字("退出帐号");
        sleep(2000)
        //防止退出加载不出来，不能用while
        click("退出帐号")
        sleep(3000)
        launchApp("设置");
    }
}

function 登陆华为账号(a, b) {
    
    //登陆华为账号*************************************************
    if (text("登录华为帐号").findOne(100)) {
         log("登录华为帐号")
        sleep(2000);
        while (!click("登录华为帐号"));

        sleep(2000);
        获取账号();
        while (!setText(0, str));
        while (!input(1, "Hw@12576"));
        sleep(1000)
        点击文字("登录");
    
        if (!text("获取验证码").findOne(60000)) {
            拨号换ip();

            launchApp("设置");
            sleep(1000);

        } else {
            var flag=true;
            while (!textContains("好友与联系人").exists()) {
                if (textContains("正在加载云空间").findOne(100)) {
                    back();
                }

                if (text("华为帐号、付款与账单、云空间等").findOne(100)) {
                    点击文字("华为帐号、付款与账单、云空间等");
                }
                if (textContains("无法连接服务器，请点击屏幕重试").exists()) {
                    click(407, 960);
                }

                dl = textContains("帐号或密码错误").findOne(100);
                if (dl) {
                    console.log("帐号或密码错误,重新获取账号");
                    异常账号数量 += 1;
                    launchApp("设置");
                    flag=false;
                    break;
                }
                //账号绑定手机号，换下一个账号并记录
                if (text("选择其他验证方式").findOne(100)) {
                    console.log("该账号已绑定手机号，重新获取账号");
                    异常账号数量 += 1;
                    launchApp("设置");
                    flag=false;
                    break;
                }
                 if(textContains("请输入正确的验证码").findOne(100)){
                  launchApp("设置");
                  异常账号数量 += 1;
                 log("验证码错误");
                 flag=false;
                 break;
                 }
                dl = text("获取验证码").findOne(100);
                if (dl) {
                    while (!click("获取验证码"));

                    while (1) {
                        try {
                            r = http.get("http://web.wwsd.top/api/email/readEmail?email=" + str);
                            sleep(2000);
                            r = http.get("http://shopapi.wwsd.top/api/email/getRead?email=" + str + "&password=Hw@12576");
                            r = r.body.string();
                        } catch (err) {
                            r = http.get("http://web.wwsd.top/api/email/readEmail?email=" + str);
                            sleep(2000);
                            r = http.get("http://shopapi.wwsd.top/api/email/getRead?email=" + str + "&password=Hw@12576");
                            r = r.body.string();
                        }
                        console.log("正在获取验证码");
                        click("重新获取");
                        if (r.search("<b>") != -1) {
                            var code = r.split("<b>")[1].split("<")[0];
                            console.log("验证码" + code);
                            while (!setText(0, code));
                            点击文字("确定")
                            sleep(2000)

                            break;
       
                        }
                    }

                }


            }
           //********************* */
            
            if (flag&&textContains("好友与联系人").findOne()) {
                launchApp("华为钱包")
               更改注册地1(a,b)
        
      

            }
            //********************* */

        }
    }

}
function 更改注册地1(a,b) {
    
   
   
        if (text("以下为已开通服务的国家/地区").findOne(60000)) {
            console.log();
            sleep(2000)
            click(500,580);
            sleep(2000)
            click(550,550)
                
                if (textContains("切换成功").findOne(30000)){
                    console.log("切换地区成功");
                    sleep(10000)
                    操作app("停止",("华为钱包"))
                    打开小华花圃(a,b);;
                    console.log("打开小华花圃,邀请" + b); 
                }else{
                    操作app("停止",("华为钱包"))
                    打开小华花圃(a,b);;
                    console.log("打开小华花圃,邀请" + b); 
                }
            


        }else{
            操作app("停止",("华为钱包"))
            打开小华花圃(a,b);;
            console.log("打开小华花圃,邀请" + b); 
        }
    
    

}
function 更改注册地(a,b) {
    while (!textContains("使用移动数据网络").findOne(100)){
        app.startActivity({
            packageName: "com.huawei.appmarket",
            className: "com.huawei.appmarket.service.settings.view.activity.SettingsActivity",
            root: true
        });
        sleep(5000)
    }
    swipe(500, 1700, 500, 400, 500)
    sleep(2000)
    swipe(500, 1700, 500, 400, 500)
    sleep(2000)
   if (text("国家/地区").findOne(1000)) {
   if (!text("中国").findOne(1000)) {
        sleep(1000)
        点击文字("国家/地区")
        if (text("以下为已开通服务的国家/地区").findOne(30000)) {
            sleep(2000)
            while (!setText(0, "中国"));
            sleep(2000)
            click(550,550)
                
                if (textContains("您当前选择的国家/地区为中国").findOne(30000)){
                    打开小华花圃(a,b);;
                    console.log("打开小华花圃,邀请" + b); 
                }else{
                    打开小华花圃(a,b);;
                    console.log("打开小华花圃,邀请" + b); 
                }
            


        }else{
            更改注册地(a,b)

        }
    }else{
        
         打开小华花圃(a,b);;
        }
    }else{
        更改注册地(a,b)

    }

}

 function 重启换ip() {
    // log("换ip")
    var url = "https://gw.smart.jd.com/f/service/controlDevice?hard_platform=TNY-AL00&app_version=6.5.5&device_id=3412F98F08CE&plat_version=10&channel=jdCloud&plat=Android"
    var headers = {
        "tgt":"AAJgF9bUAEAwLK-kZTAlAROZn17iqJyr0l5gBqhNSqgTeqDOifotixc4Odzm4sgR5GhVAXNYlbZXBiPLB_gg9VMwii1WY227" ,
"Authorization":"smart b8f9c108c190a39760e1b4e373208af5cd75feb4:::Ta4Ynajj4jzfzVweVUfrcHvSQr4=:::2021-08-29T11:24:40.178Z" ,
 "accesskey":"b8f9c108c190a39760e1b4e373208af5cd75feb4" ,
  "pin":"jd_53c4eb281ed8e" ,
  "signature":"EB740F293150EDDF027FFEE0F01EF119" ,
  "identity":"979F9366CCD66745FDC38F91F6E3DF92" ,
  "appkey":"996" ,
   //"timestamp":"2021-08-29 11:24:40" ,
   "Content-Type":"application/json" ,
   "User-Agent":"Dalvik/2.1.0 (Linux; U; Android 10; TNY-AL00 Build/HUAWEITNY-AL00)" ,
    "Host":"gw.smart.jd.com" ,
    "Connection":"Keep-Alive" ,
    "Accept-Encoding":"gzip" ,
     "Content-Length":"110"
    }
    var data ={
        "feed_id":"914961612175250289",
        "command":[{"current_value":{"cmd":"reboot_system"},"stream_id":"SetParams"}]
        }
     

    var res = http.postJson(url, data, {
        headers: headers
    })
    log(res.body.string())
    home()
    sleep(60000)
  
}
function 拨号换ip() {
    // log("换ip")
    var url = "http://jdcloudwifi.com:54171/api/api_wrapper"
    var headers = {
        // "User-Agent":"Mozilla/5.0(Linux;Android 10; TNY-AL00 Build/HUAWEITNY-AL00; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/83.0.4103.106 Mobile Safari/537.36 (JBOX-APP; Android/2.8.2/44)",
        "Referer": "http://guanli.luyou.360.cn/new_index.htm",
        "Connection": "close",
        "jdmt-rx-sign": "6b13af811e6b0eadb95198da152c1768",
        "jdmt-rx-time": "1625887050479",
        "jdmt-rx-appKey": "fe2c20725c261e49a80d707a6ab299e1",
        "wskey": "AAJgF9bUAEAwLK-kZTAlAROZn17iqJyr0l5gBqhNSqgTeqDOifotixc4Odzm4sgR5GhVAXNYlbZXBiPLB_gg9VMwii1WY227",
        "Cookie": "d2admin-1.5.6-uuid=;d2admin-1.5.6-token=83472e0783b45f6bf4272762bfb55637",
        "Content-Type": "application/json",
        "Content-Length": "170",
        "Host": "jdcloudwifi.com:54171",
        "Accept-Encoding": "gzip"
    }
    var data = {
        "action": "call",
        "payload": [{ "data": { "mtu": random(1480, 1492), "password": "854647", "peerdns": true, "proto": "pppoe", "username": "18703854647" }, "method": "wan.set_proto" }],
        "version": "1.0.0"
    }
  try{
    var res = http.postJson(url, data, {
        headers: headers
    })
    log(res.body.string())
    home()
    sleep(50000)
      }catch(err){
        重启换ip()
        
        }
    
}
function 点击文字(文字) {
    sleep(1000);
    var 点击的文字 = text(文字).findOne(5000);
    if (点击的文字) {
        var x = 点击的文字.bounds().centerX();
        var y = 点击的文字.bounds().centerY();
        sleep(1000);
        click(x, y);
        console.log("已点击" + 文字);
    } else {
        console.log("未发现" + 文字);
    }

}
function 子线程点击文字(查找文字, 点击文字) {

    if (textContains(查找文字).findOne(100)) {
        var 点击的文字 = text(点击文字).findOne(1000);
        if (点击的文字) {
            var x = 点击的文字.bounds().centerX();
            var y = 点击的文字.bounds().centerY();
            click(x, y);
            console.log("已点击" + 点击文字);
        }

    }

}

function 清除应用市场数据() {
    openAppSetting(getPackageName("华为应用市场"));

        点击文字("存储");
        点击文字("删除数据");
        点击文字("确定");
        launchApp("设置");
    }



function 打开小华花圃(邀请链接,邀请编号) {

    sleep(3000)
    log("打开花圃")
    app.startActivity({
        action: "android.intent.action.VIEW",
        data: 'hiapp://com.huawei.appmarket?activityName=activityUri|webview.activity&params={"params":[{"name":"url","type":"String","value":"' + encodeURIComponent(邀请链接) + '"},{"name":"uri","type":"String","value":"external_webview"}]}&channelId=',
        packageName: "com.huawei.appmarket"
    });
    sleep(3000)
    var time = new Date().valueOf();
    while (1) {
       
        //log("跳转花圃")
        click("同意")
        if (textContains("开始种花").findOne(100)) {
            click("开始种花");
        }
        if (textContains("自动读取短信验证码").findOne(100)) {
            launchApp("设置");
        }

        if (textContains("开始采蜜").findOne(100)) {
            sleep(2000);
            back();
        }
        if (textContains("未登录").findOne(100)) {
            sleep(2000);
            清除应用市场数据()
            log("未登录")
            //操作app("停止", "华为应用市场")
           // 更改钱包地区()
            break
        }
        if (textContains("30g").findOne(100)) {
            console.log("发现30g");
            sleep(1000);
            click(900, 2000);
            click(900, 2000);
            sleep(1000);
            正常签到数量 += 1;
            log("已邀请" + 正常签到数量);
            //if(正常签到数量==9){
               // 微信通知("已刷至第"+邀请编号+"个账号") 
              //  }
              清除应用市场数据()

            console.log("第" + 正常签到数量 + "个邀请完成");

         
            break

        }
        //账号已使用
        if (textContains("20g").findOne(100) || text("恭喜获得0g水滴").findOne(100)) {
            console.log("20g账号已使用");
            异常账号数量 += 1;

            sleep(3000);
            清除应用市场数据()
            sleep(1000);
            break
        }
        if (textContains("0g").findOne(100)) {
            click(858, 1105);
        }
        var time1 = new Date().valueOf();
        if (time1 - time > 60000) {
            清除应用市场数据()

            console.log("未成功加载花圃");
            break
        }
    }
}


function 重启设置() {
    console.log("重启设置");
    var intent1 = new Intent();
    intent1.setAction("android.settings.APPLICATION_SETTINGS");
    app.startActivity(intent1);
    sleep(10000);
    setText("设置");
    sleep(1000);
    click("设置", 1);
    sleep(1000);
    点击文字("强行停止");
    点击文字("强行停止");
    sleep(5000);
}





function 操作app(操作, app名称) {
    var 包名 = getPackageName(app名称);
    switch (操作) {
        case "启动":
            shell('am start ' + 包名, true);
            sleep(10000)
            break;
        case "清理":
            shell('pm clear  ' + 包名, true);
            sleep(10000)
            break;
        case "卸载":
            shell('pm uninstall ' + 包名, true);
            sleep(10000)
            break;
        case "停止":
            shell('am force-stop ' + 包名, true);
            sleep(10000)
            break;
    }
}




